package com.yunxin.core.infra.persistence.repository.channel;

import com.yunxin.core.domain.model.channel.ChannelCustomerApplyLibraryRecord;
import com.yunxin.core.domain.model.channel.ChannelCustomerApplyLibraryRecordRepository;
import com.yunxin.core.infra.persistence.converter.ChannelConvertor;
import com.yunxin.core.infra.persistence.entity.channel.ChannelCustomerApplyLibraryRecordDO;
import com.yunxin.core.infra.persistence.mapper.channel.ChannelCustomerApplyLibraryRecordExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2023-12-14
 */
@Repository
@RequiredArgsConstructor
public class ChannelCustomerApplyLibraryRecordRepositoryImpl implements ChannelCustomerApplyLibraryRecordRepository {

    private final ChannelConvertor channelConvertor;

    private final ChannelCustomerApplyLibraryRecordExtendMapper channelCustomerApplyLibraryRecordExtendMapper;
    @Override
    public boolean saveChannelCustomerApplyLibraryRecord(ChannelCustomerApplyLibraryRecord channelCustomerApplyLibraryRecord) {
        ChannelCustomerApplyLibraryRecordDO channelCustomerApplyLibraryRecordDO = channelConvertor.formChannelCustomerApplyLibraryRecord(channelCustomerApplyLibraryRecord);
        int result = channelCustomerApplyLibraryRecordExtendMapper.insertSelective(channelCustomerApplyLibraryRecordDO);
        return result > 0;
    }

    @Override
    public boolean updateChannelCustomerApplyLibraryRecord(ChannelCustomerApplyLibraryRecord channelCustomerApplyLibraryRecord) {
        ChannelCustomerApplyLibraryRecordDO channelCustomerApplyLibraryRecordDO = channelConvertor.formChannelCustomerApplyLibraryRecord(channelCustomerApplyLibraryRecord);
        int result = channelCustomerApplyLibraryRecordExtendMapper.updateByPrimaryKeySelective(channelCustomerApplyLibraryRecordDO);
        return result > 0;
    }

    @Override
    public ChannelCustomerApplyLibraryRecord getChannelCustomerApplyLibraryRecordByLibraryNo(String libraryNo) {
        ChannelCustomerApplyLibraryRecordDO channelCustomerApplyLibraryRecordDO = channelCustomerApplyLibraryRecordExtendMapper.selectByLibraryNo(libraryNo);
        return channelConvertor.toChannelCustomerApplyLibraryRecord(channelCustomerApplyLibraryRecordDO);
    }
}
